//
//  SXTMyMessageTableView.m
//  SXT
//
//  Created by gaochar on 2017/3/18.
//  Copyright © 2017年 so. All rights reserved.
//

#import "SXTMyMessageTableView.h"
/**
 列表中的自定义cell
 */
#import "SXTMyMessageTableViewCell.h"

@interface SXTMyMessageTableView () <UITableViewDelegate, UITableViewDataSource>
/**
 message列表需要展示的数据源
 */
@property (nonatomic, strong) NSArray *messageTableSource;
@end

@implementation SXTMyMessageTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.bounces = NO;
    }
    return self;
}

- (NSArray *)messageTableSource {
    if (!_messageTableSource) {
        _messageTableSource = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SXTMyMessageTablePlist" ofType:@"plist"]];
    }
    return _messageTableSource;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    SXTMyMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[SXTMyMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.sourceDic = self.messageTableSource[indexPath.row];
    
    if (indexPath.row == 3) {
        UIImageView *nextImage = [cell valueForKey:@"nextImage"];
        nextImage.hidden = YES;
        
        UILabel *phoneNum = [[UILabel alloc] init];
        phoneNum.textColor = RGB(123, 124, 128);
        phoneNum.text = @"400-100-1111";
        [cell addSubview:phoneNum];
        
        __weak typeof (cell) weakSelf = cell;
        [phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mas_right).offset(-15);
            make.centerY.equalTo(weakSelf.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(110, 15));
        }];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SXTLog(@"我选中的是第%li行", indexPath.row);
}

@end
